/* 贪心算法 圣诞老人的礼物 */

#include<iostream>
#include<algorithm>
using namespace std;

struct TGift
{
	double worth;
	double weight;
};

struct Comp
{
	bool operator()(const TGift &lhs, const TGift &rhs)
	{
		return ((lhs.worth / lhs.weight) < (rhs.worth / rhs.weight));
	}
};

int main(void)
{
	constexpr int N = 4;
	int w = 15;

	/* 问题描述：
	 * 从N种礼物中，选出总重量为w的礼物，使总价值最高。
	 * 每种礼物都可以拆分，只取其中一部分 */
	TGift gifts[N] = {
		{100, 4},
		{412, 8},
		{266, 7},
		{591, 2}
	};

	sort(gifts, gifts + N, Comp{});
	

	double totalWeight = 0;
	double totalWorth  = 0;
	for (int i = 0; i < N; i++)
	{
		TGift *pt = &gifts[N - 1 - i];

		if (totalWeight + pt->weight <= w)
		{
			totalWeight += pt->weight;
			totalWorth += pt->worth;
		}
		else
		{
			totalWorth += (pt->worth / pt->weight) * (w - totalWeight);
			totalWeight = w;
			break;
		}
	}
	
	cout<< totalWorth <<endl;

	return 0;
}
